package com.coocaa.ops.admin.v1.policygroup.biz.impl;

import com.coocaa.ops.admin.v1.policygroup.biz.IPolicyGroupChipModelConfigBiz;
import com.coocaa.ops.admin.v1.policygroup.convert.PolicyGroupSaveConverter;
import com.coocaa.ops.admin.v1.policygroup.mapper.IPolicyGroupChipModelConfigMapper;
import com.coocaa.ops.common.core.base.BaseBizImpl;
import com.coocaa.ops.common.core.base.mybatis.QueryTemplate;
import com.coocaa.ops.common.core.biz.policygroup.entity.PolicyGroupChipModelConfigEntity;
import com.coocaa.ops.common.core.biz.policygroup.entity.PolicyGroupInfoEntity;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author bjh
 * @description 策略组机型机芯配置表-biz层接口实现
 * @date 2020-03-12 14:46:25
 */
@Service
public class PolicyGroupChipModelConfigBizImpl extends BaseBizImpl<IPolicyGroupChipModelConfigMapper, PolicyGroupChipModelConfigEntity> implements IPolicyGroupChipModelConfigBiz {

    @Override
    public void saveModelChipRls(PolicyGroupInfoEntity policyGroupInfoEntity) {
        List<PolicyGroupChipModelConfigEntity> saveList = PolicyGroupSaveConverter.getFinalModelChipList(policyGroupInfoEntity);
        this.saveBatchAvoidEmpty(saveList);
    }

    @Override
    public List<PolicyGroupChipModelConfigEntity> queryChipModelList(Integer id, Integer version) {
        QueryTemplate<PolicyGroupChipModelConfigEntity> queryTemplate = this.getQuery(id, version);
        List<PolicyGroupChipModelConfigEntity> rlsModelChipList = this.getMapper().selectList(queryTemplate);
        return rlsModelChipList;
    }

    @Override
    public void deleteRls(Integer id, Integer version) {
        QueryTemplate<PolicyGroupChipModelConfigEntity> queryTemplate = this.getQuery(id, version);
        this.getMapper().delete(queryTemplate);
    }

    @Override
    public void logicDeleteRls(Integer id, Integer version,Integer userId) {
        QueryTemplate<PolicyGroupChipModelConfigEntity> queryTemplate = this.getQuery(id, version);
        PolicyGroupChipModelConfigEntity update = new PolicyGroupChipModelConfigEntity();
        update.setFlag(0);
        update.setModifier(userId);
        this.getMapper().update(update, queryTemplate);
    }

    private QueryTemplate<PolicyGroupChipModelConfigEntity> getQuery(Integer id, Integer version) {
        QueryTemplate<PolicyGroupChipModelConfigEntity> queryTemplate = QueryTemplate.getEqQueryTemplate("flag", 1);
        queryTemplate.eq("policy_group_id", id);
        queryTemplate.eq("policy_group_version", version);
        return queryTemplate;
    }
}
